﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Game1942.Library.Weapons;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Point = Game1942.Library.Background.Point;

namespace Game1942.Library.View
{
    public class ComputerElementView : IObserver<ComputerElement>, IView
    {
        private Texture2D ammoTexture;
        private Point position;
        private Boolean visible;
        private IDisposable unsubscriber;
        private int width, height;

        public ComputerElementView(Point aPosition, int width,int height)
        {
            position = aPosition;
            this.width = width;
            this.height = height;
            visible = true;
        }

        public void LoadContent(Texture2D aTexture)
        {
            ammoTexture = aTexture;
        }

        public void Draw(SpriteBatch sprite)
        {
            sprite.Draw(ammoTexture, new Rectangle(position.X, position.Y, width, height), Color.White);
        }

        public bool Visible()
        {
            return visible;
        }

        #region [Observer Methods]

        public void Subscribe(IObservable<ComputerElement> provider)
        {
            if (provider != null)
                unsubscriber = provider.Subscribe(this);
        }

        public void OnNext(ComputerElement value)
        {
            position = value.ActualPosition;
            visible = value.Alive;
        }

        public void OnError(Exception error)
        {
            //Do nothing
        }

        public void OnCompleted()
        {
            unsubscriber.Dispose();
        }

        #endregion

    }
}
